#ifndef IVSMODEL_H
#define IVSMODEL_H

#include <QObject>
#include <QList>
#include <QColor>
#include "cv.h"
#include "alghelper.h"
#include "videosourcesetting.h"
#include "ivssetting.h"
#include "logger.h"

class IVSModel : public QObject, public VideoSourceSetting, public IVSSetting
{
    Q_OBJECT
public:
    explicit IVSModel(QObject *parent = 0);
    static void log(QString logContent);
    int CurrentVideoSourceIndex(int index = -1);
    QStringList ListVideoSourceName();

    /* getters */
    IVS::VideoSource getCurrentVideoSource();
    IVS::VideoSource CurrentVideoSource();
    IVS::eFunctions CurrentFunction();

    /* setters */
    int addNewVideoSource(QString _videoSourceName);
    void setSource(QString _source);
    void setSourceType(IVS::eVideoSourceType _videoSourceType);
    void setROI(QList<CvPoint> _ROI);
    bool toogleMakingROI();
    bool IsMakingROI();
    void ROI_add_point(int x, int y);

    /* IVS Settings */
    IVSSettings::Video_player_settings VideoPlayerSettings();
    void setVideoPlayerSettings_EnableROI(bool _isEnableROI);
    IVSSettings::Intruders_detection_settings IntrudersDetectionSettings();
    void setIntrudersDetectionSettings_NoFrameToInitBG(int nFrame);
    void setIntrudersDetectionSettings_Alpha(float alpha);
    void setIntrudersDetectionSettings_StateChangeDelay(int nFrame);
    void setIntrudersDetectionSettings_BoundRectAreaMin(int bnRectAreaMin);
    void setIntrudersDetectionSettings_BoundRectAreaMax(int bnRectAreaMax);
    void setIntrudersDetectionSettings_NoBin(int noBin);
    IVSSettings::Restricted_area_survuillance_settings RestrictedAreaSurvuillanceSettings();
    void setRestrictedAreaSurvuillanceSettings_NoFrameToInitBG(int nFrame);
    void setRestrictedAreaSurvuillanceSettings_Alpha(float alpha);
    void setRestrictedAreaSurvuillanceSettings_StateChangeDelay(int nFrame);
    void setRestrictedAreaSurvuillanceSettings_BoundRectAreaMin(int bnRectAreaMin);
    void setRestrictedAreaSurvuillanceSettings_BoundRectAreaMax(int bnRectAreaMax);
    void setRestrictedAreaSurvuillanceSettings_NoBin(int noBin);
    IVSSettings::Camera_checks_settings CameraChecksSettings();
    void setCameraChecksSettings_NoFrameToInitBG(int nFrame);
    void setCameraChecksSettings_Apla(float alpha);
    void setCameraChecksSettings_StateChangeDelay(int nFrame);
    void setCameraChecksSettings_VideoPlaySpeedBoost(int fps);
    void setCameraChecksSettings_BeCoveredThreshold(int illumination);

    /*
    IVSSettings::Fence_survuillance_settings fence_survuillance_settings;
    IVSSettings::People_counting_settings people_counting_settings;
    IVSSettings::People_tracking_settings people_tracking_settings ;
    IVSSettings::Theft_detection_settings theft_detection_settings;
    IVSSettings::Object_left_behide_detection_settings object_left_behide_detection_settings;
    */
private:
    int currentVideoSourceIndex;
    IVS::eFunctions currentFunction;

    bool validateCurrentIndex();
    bool isMakingROI;
    IVS::VideoSource getDefaultVideoSource(QString _videoSourceName);
    IVS::VideoSource getEmptyVideoSource();


public slots:
    void setCurrentFunction(IVS::eFunctions _currentFuntion);
    void setCurrentVideoSource(QString _currentVideoSourceName);
    void saveAllSettings();
    void setVerboseLevel(QString _verboseLevelText);

signals:
    void updateVideoSource();
    void updateCurrentFunction();
    void updateCurrentFunctionSettings();
    void updateROI(bool isComplete);
    void stateChanged(QString msg, QColor color);

};

#endif // IVSMODEL_H
